<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>资金明细</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/my.css/}" media="all">
    <style>
        .childrenBody{
            padding: 30px;
        }
        a{
            cursor:pointer;
        }
    </style>
</head>
<body class="childrenBody">
    <div class="my-btn-box layui-form">
        <span class="fr">
            <div class="layui-input-inline">
              <input type="text" name="ctime" autocomplete="off" class="layui-input height33" id="ctimeId"  placeholder="创建时间">
            </div>
            <button class="layui-btn layui-btn-sm" id="search"><i class="layui-icon">&#xe615;</i>搜索</button>
        </span>
    </div>
    <div class="layui-tab layui-tab-brief" lay-filter="test1">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="">全部</li>
            <li lay-id="0">支出</li>
            <li lay-id="1">收入</li>
        </ul>
        <div class="layui-tab-content">
            <!-- 表格 -->
            <div id="dataTable" lay-filter="event"></div>
            <div class="height50"></div>
        </div>
    </div>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/fyn/index.js}"></script>
<script th:src="@{/js/fyn/my.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>
<script type="text/javascript" th:src="@{/js/vip/vip_table.js}"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(['table', 'form', 'laypage', 'layer', 'element','laydate'], function () {
        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , element = layui.element
            , laydate = layui.laydate
            , $ = layui.jquery;

        //创建时间
        var ctime = laydate.render({
            elem: '#ctimeId',
            type: 'date',
            format: 'yyyy-MM-dd',
            trigger:'click',
            value: '',
            done: function(value, date){
            }
        });

        var balanceType = null;

        //获取hash来切换选项卡，假设当前地址的hash为lay-id对应的值
        var layid = location.hash.replace(/^#test1=/, '');
        element.tabChange('test1', layid);

        // Tab 切换，以改变地址 hash 值
        element.on('tab(test1)', function(){
            var layId = this.getAttribute('lay-id');
            console.log(layId);
            balanceType = layId;
            // 重新刷新表格
            tableIns.reload({
                where: {
                    type: balanceType
                    ,userId: [[${user.id}]]
                    ,ctime: $("#ctimeId").val()
                },
                page: {
                    curr: 1
                }
            });
        });

        // 表格渲染
        var tableIns = table.render({
            elem: '#dataTable'
            , height: "full"
            // , skin: 'line'
            , even: 'true'
            , cols: [[                  //标题栏
                // {field: 'id', title: 'ID', minWidth: '100', align: 'center'},
                {
                    field: 'user.id', title: '收支类型', minWidth: '100', align: 'center', templet: function (d) {
                        return  (d.type == 0 ? '系统充值' : d.type == 1 ? '系统提现' : d.type === 2 ? '发送红包' :  d.type === 3 ? '领取红包' : '其他');
                    }
                },
                {
                    field: 'user.id', title: '红包类型', minWidth: '100', align: 'center', templet: function (d) {
                        return d.packet == null ? "" : (d.packet.type === 0 ? '单聊' : d.packet.type === 1 ? '群聊' : d.packet.type === 2 ? '转账' : d.packet.type === 3 ? "群专属" : "未知");
                    }
                },
                {field: 'moneyDesc', title: '金额', minWidth: '100', align: 'center'},
                {field: 'sendUserId', title: '发送人ID', minWidth: '100', align: 'center', templet: function (d) {
                        return (d.type == 2 || d.type == 3) ? "<a onclick='showPersion("+d.sendUserId+");' style='color: #00C0F7'>"+d.sendUserId+"</a>" : '';
                }},
                {field: 'sendUserName', title: '发送人', minWidth: '100', align: 'center'},
                {field: 'receiveUserId', title: '接收人ID', minWidth: '100', align: 'center', templet: function (d) {
                    if (d.type == 2 || d.type == 3) {
                        if (d.packet) {
                            return (d.packet.type === 0 || d.packet.type === 3 || d.packet.type === 2) ? "<a onclick='showPersion("+d.receiveUserId+");' style='color: #00C0F7'>"+d.receiveUserId+"</a>" : "<a style='color: #00C0F7' onclick=\"showGroupReceive("+d.packet.id+")\">群聊ID["+d.receiveUserId+"]</a>";
                        }
                        return "";
                    }
                        return "";
                }},
                {field: 'receiveUserName', title: '接收人', minWidth: '100', align: 'center'},
                {field: 'receiveState', title: '领取状态', minWidth: '100', align: 'center', templet: function (d) {
                    var state = d.receiveState;
                    var overState = d.receiveOverState;

                    if (null == state || null == overState) {
                        return "";
                    }

                    // 群聊
                    if (d.packet.type == 1) {
                        return overState == 0 ? "未领取完" : "已领取完";
                    }else {
                        return overState == 0 ? "未领取" : "已领取";
                    }

                }},
                {field: 'balance', title: '余额', minWidth: '100', align: 'center'},
                {field: 'memo', title: '描述', minWidth: '100', align: 'center'},
                {field: 'ctime', title: '创建时间', minWidth: '100', align: 'center'}
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/balance/detail/list'
            , method: 'get'
            , page: true
            , limits: [10, 30, 60, 90, 150, 300]
            , limit: 10 //默认采用0
            , loading: true
            , where: getJson()
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                $("td[data-field='content']").each(function () {
                    $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                });
            }
        });

        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'groupMember') {
                layer.open({
                    type: 2,
                    title: '领取列表',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['650px', '550px'],
                    content: [[${basePath}]] + '/packet/receive/index?id=' + data.packet.id
                });

            }
        });

        $("#search").click(function () {
            tableIns.reload({
                where: {
                    type: balanceType
                    ,userId: [[${user.id}]]
                    ,ctime: $("#ctimeId").val()
                },
                page: {
                    curr: 1
                }
            });
        });

        function getJson() {
            return {
                type: balanceType
                ,userId: [[${user.id}]]
                ,ctime: $("#ctimeId").val()
            };
        }

    });

    // 查看群聊领取红包列表
    function showGroupReceive(packetId) {
        layer.open({
            type: 2,
            title: '领取列表',
            shadeClose: true,
            shade: 0.2,
            maxmin: true, //开启最大化最小化按钮
            area: ['100%', '100%'],
            content: [[${basePath}]] + '/packet/receive/index?id=' + packetId
        });
    }

    // 点击收发人id 进入其对应的收支详情
    function showPersion(receiveUserId) {
        if (!receiveUserId) {
            return;
        }
        // 关闭子页面中的弹框
        var index = layer.closeAll ();
        // 关闭父页面中的弹框
        parent.layer.close (index);

        layer.open({
            type: 2,
            title: '资金明细',
            shadeClose: true,
            shade: 0.2,
            maxmin: true, //开启最大化最小化按钮
            area: ['100%', '100%'],
            content: [[${basePath}]] + '/member/fundDetails?userId=' + receiveUserId
        });
    }

</script>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barOption">
</script>
</body>
</html>